home *** CD-ROM | disk | FTP | other *** search
/ APDL Eductation Resources / APDL Eductation Resources.iso / programs / electronic / rlab / !RLaB / RISC_OS / gnpltst_sm next >
Encoding:
Text File  |  1995-10-17  |  4.9 KB  |  259 lines

  1.  # A RISC OS specific scaled down GNUPlot test script
  2.  
  3.  #
  4.  # Test 2-D plots
  5.  #
  6.  
  7.  printf (" Have you got a gnuplot-3.5 patched with multiplot and border? (y/n) (def. no) ");
  8.  ans = getline ("stdin");
  9.  
  10.  x = (0.25:4:.25)';
  11.  
  12.  //-----------------------------------------------------------------//
  13.  autoscale();
  14.  title ("Multiple Line Colors and Styles");
  15.  linestyle ("line");
  16.  nogrid();
  17.  xlabel ("X-axis Label");
  18.  ylabel ("Y-axis Label");
  19.  plot ( [x, x, 2*x, 3*x] );
  20.  pause ("Type RETURN to continue");
  21.  
  22.  title ("Multiple Point Colors and Styles");
  23.  linestyle ("point");
  24.  nogrid();
  25.  plot ( [x, x, 2*x, 3*x] );
  26.  pause ("Type RETURN to continue");
  27.  
  28.  title ("Multiple Line-Point Colors and Styles");
  29.  linestyle ("linespoint");
  30.  grid();
  31.  plot ( [x, x, 2*x, 3*x] );
  32.  pause ("Type RETURN to continue");
  33.  
  34.  title ("Multiple Line-Point Colors and Styles");
  35.  linestyle ("lines");
  36.  nogrid();
  37.  plot ( [x, x] );
  38.  linestyle ("point");
  39.  replot ( [x, 2*x] );
  40.  linestyle ("linespoint");
  41.  replot ( [x, 3*x] );
  42.  pause ("Type RETURN to continue");
  43.  
  44.  nogrid();
  45.  //-----------------------------------------------------------------//
  46.  # Show off axis types
  47.  title("Linear Axes");
  48.  grid();
  49.  nolog();
  50.  plot ([x,exp(-x*0.5)]);
  51.  pause ("Type RETURN to continue");
  52.  
  53.  title("Log X - Axis");
  54.  grid();
  55.  semilogx();
  56.  plot ([x,exp(-x*0.5)]);
  57.  pause ("Type RETURN to continue");
  58.  
  59.  title("Log Y - Axis");
  60.  grid();
  61.  semilogy();
  62.  plot ([x,exp(-x*0.5)]);
  63.  pause ("Type RETURN to continue");
  64.  
  65.  title("Log  Axes");
  66.  loglog();
  67.  grid();
  68.  plot ([x,exp(-x*0.5)]);
  69.  pause ("Type RETURN to continue");
  70.  
  71.  nolog();
  72.  nogrid();
  73.  
  74.  //-----------------------------------------------------------------//
  75.  pause ("Type RETURN to continue");
  76.  autoscale();
  77.  
  78.  //-----------------------------------------------------------------//
  79.  # Make 3D data
  80.  
  81.  # Sombrero
  82.  
  83.  NX = 20;
  84.  NY = 20;
  85.  xx = zeros (1, NX);
  86.  yy = zeros (1, NY);
  87.  for (i in 1:NX) { xx[i] = (i - NX/2)/(NX/2); }
  88.  for (i in 1:NY) { yy[i] = (i - NY/2)/(NY/2); }
  89.  
  90.  zz = zeros (NX, NY);
  91.  
  92.  for (i in 1:NX)
  93.  {
  94.      for (j in 1:NY)
  95.      {
  96.      r = sqrt (xx[i]^2 + yy[j]^2);
  97.      zz[i;j] = exp (-r * r) * cos (2*pi*r);
  98.      }
  99.  }
  100.  
  101.  # Now create some plots
  102.  
  103.  title("3-D Plot, Sombrero");
  104.  grid();
  105.  splot(xx,yy,zz);
  106.  pause ("Type RETURN to continue");
  107.  
  108.  
  109.  # Sin - Cos surface
  110.  
  111.  x1 = -3:3:.2;
  112.  y1 = -3:3:.2;
  113.  z1 = zeros (x1.n, y1.n);
  114.  
  115.  for (i in 1:x1.n)
  116.  {
  117.      for(j in 1:y1.n)
  118.      {
  119.      z1[i;j] = sin(y1[j]) * cos(x1[i]);
  120.      }
  121.  }
  122.  
  123.  title("3-D Plot, Cos-Sine Surface");
  124.  nogrid();
  125.  splot(x1,y1,z1);
  126.  pause ("Type RETURN to continue");
  127.  
  128.  
  129.  # Slanted plane
  130.  
  131.  x2 = 1:10;
  132.  y2 = 1:10;
  133.  z2 = zeros (x2.n, y2.n);
  134.  for (i in 1:x2.n) { z2[i;] = i*ones(1,y2.n); }
  135.  
  136.  title("3-D Plot, Plane");
  137.  splot(x2,y2,z2);
  138.  pause ("Type RETURN to continue");
  139.  
  140.  
  141.  # Two Slanted planes
  142.  z3 = -2*z2;
  143.  title("3-D Plot, 2 - Planes");
  144.  splot(x2,y2,[z2',z3]);
  145.  pause ("Type RETURN to continue");
  146.  
  147.  
  148.  
  149.  //-----------------------------------------------------------------//
  150.  
  151.  #
  152.  # Simple contour plotting demonstration
  153.  #
  154.  
  155.  NX = 20;
  156.  NY = 20;
  157.  xx = zeros (1, NX);
  158.  yy = zeros (1, NY);
  159.  for (i in 1:NX) { xx[i] = (i - NX/2)/(NX/2); }
  160.  for (i in 1:NY) { yy[i] = (i - NY/2)/(NY/2); }
  161.  
  162.  zz = zeros (NX, NY);
  163.  
  164.  for (i in 1:NX)
  165.  {
  166.      for (j in 1:NY)
  167.      {
  168.      r = sqrt (xx[i]^2 + yy[j]^2);
  169.      zz[i;j] = exp (-r * r) * cos (2*pi*r);
  170.      }
  171.  }
  172.  
  173.  # Sin - Cos surface
  174.  
  175.  x1 = -3:3:.2;
  176.  y1 = -3:3:.2;
  177.  z1 = zeros (x1.n, y1.n);
  178.  
  179.  for (i in 1:x1.n)
  180.  {
  181.      for(j in 1:y1.n)
  182.      {
  183.      z1[i;j] = sin(y1[j]) * cos(x1[i]);
  184.      }
  185.  }
  186.  
  187.  # Now create some plots
  188.  
  189.  xlabel("X-Axis");
  190.  ylabel("Y-Axis");
  191.  title ("Contour Demonstration");
  192.  cont(xx,yy,zz);
  193.  pause ("Type RETURN to continue");
  194.  
  195.  xlabel("X-Axis");
  196.  ylabel("Y-Axis");
  197.  title ("Contour Demonstration");
  198.  cont (x1,y1,z1);
  199.  pause ("Type RETURN to continue");
  200.  
  201.  
  202.  //-----------------------------------------------------------------//
  203.  
  204.  #
  205.  # demonstrate replot, multiplot and plotyy.
  206.  #
  207.  
  208.  x=0:10:0.1;
  209.  m1=[x',sin(x)'];
  210.  m2=[x',(cos(x)+1)'];
  211.  
  212.  key();
  213.  title("a sin(x).");
  214.  plot(m1,["sin(x)"]);
  215.  pause("Type RETURN to continue");
  216.  
  217.  
  218.  title("cos(x)+1 added with a replot(data) command.");
  219.  replot(m2,["cos(x)+1"]);
  220.  pause("Type RETURN to continue");
  221.  
  222.  if (ans.[1] == "y" || ans.[1] == "Y") {
  223.      title("Plot with txo y-axes");
  224.      plotyy();
  225.      key();
  226.      linestyle("lines");
  227.      ylabel("sin(x)");
  228.      plot(m1,["sin(x)"]);
  229.      ylabel("cos(x)+1");
  230.      plot(m2,["cos(x)+1"]);
  231.      pause("Type RETURN to continue");
  232.      
  233.      nokey();
  234.      ylabel ("Y-axis");
  235.      multiplot(2,2);
  236.      linestyle("lines");
  237.      title("Sombrero");
  238.      splot(xx,yy,zz);
  239.      x = (0.25:4:.25)';
  240.      y = (0.5:6:.2)';
  241.      title("Different Scales");
  242.      grid();
  243.      plot (<< [x,exp(-x*0.5)] ; [y, exp (y*0.25), exp(y*0.1)] >>);
  244.      nogrid();
  245.      plotyy();
  246.      title("Plot with txo y-axes");
  247.      ylabel("sin(x)");
  248.      plot(m1);
  249.      ylabel("cos(x)+1");
  250.      plot(m2);
  251.      xlabel("");
  252.      ylabel("");
  253.      title("Contour plot");
  254.      cont(xx,yy,zz);
  255.      pause("Type RETURN to continue");
  256.      
  257.  }
  258.  pclose(0);
  259.